package com.hushao.aimi.controller;

import com.hushao.aimi.common.ServerResponse;
import com.hushao.aimi.enumVo.ProductRecommendTypeEnum;
import com.hushao.aimi.service.RecommendService;
import com.hushao.aimi.vo.RecommendVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 推荐控制器
 * @author: 胡少
 * @create: 2018-06-06 11:33
 **/
@Api(value = "推荐信息")
@Slf4j
@RestController
@RequestMapping("/recommend")
public class RecommendController {

    @Autowired
    private RecommendService recommendService;



    /**
     * 获取推荐商品列表（分页）
     * @param productCode
     * @param pageable
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取推荐列表（分页）")
    @GetMapping
    public ServerResponse getRecommendByNameLike(@RequestParam(value = "productCode",required = false,defaultValue = "")String productCode,
                                                Pageable pageable)throws Exception{
        return recommendService.listByProductCodeLike(productCode,pageable);
    }


    /**
     * 获取推荐类型
     * @return
     */
    @ApiOperation(value = "获取推荐类型集合")
    @GetMapping("/listRecommendType")
    public ServerResponse listRecommendType(){
        return ServerResponse.Success(ProductRecommendTypeEnum.map());
    }

    /**
     * 添加推荐商品
     * @param recommendVo
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "添加推荐商品")
    @PostMapping
    public ServerResponse addRecommend(@RequestBody RecommendVo recommendVo)throws Exception{
        return recommendService.addRecommend(recommendVo);
    }

    /**
     * 删除推荐商品
     * @param recommendId
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "删除推荐商品")
    @DeleteMapping("/{recommendId}")
    public ServerResponse delRecommend(@PathVariable Integer recommendId)throws Exception{
        return recommendService.delRecommend(recommendId);
    }

    /**
     * 修改推荐商品
     * @param recommendId
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "修改推荐商品")
    @PutMapping("/{recommendId}")
    public ServerResponse update(@PathVariable Integer recommendId,@RequestBody RecommendVo recommendVo)throws Exception{
        return recommendService.updateRecommend(recommendVo);
    }

}
